package com.sport;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.sport.model.User;
import com.sport.model.UserController;

public class Results extends Activity {
	private List<User> lists = null;
	private TextView speed;
	private TextView distance;
	private TextView denivele;
	private TextView bpm;
	private TextView time;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.results);

		speed = (TextView) findViewById(R.id.averageSpeed);
		distance = (TextView) findViewById(R.id.totalDistance);
		denivele = (TextView) findViewById(R.id.totalDenivele);
		bpm = (TextView) findViewById(R.id.averageBPM);
		time = (TextView) findViewById(R.id.totalTime);

		getUsers();

	}

	@Override
	public void onPause(){
		super.onPause();
		finish();
	}

	final void getUsers() {

		UserController list = new UserController();
		try {
			lists = list.getAllUsers();
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (lists != null) {
			User u = lists.get(0);
			for (int i = 0 ; i < lists.size(); i++){
				User ub = lists.get(i);
				if (u.getDate().before(ub.getDate()))
					u = ub;
			}
			speed.setText(""+u.getSpeed());
			distance.setText(""+u.getDistance());
			denivele.setText(""+u.getDenivele());
			bpm.setText(""+u.getBpm());
			time.setText(u.getTime());
		}
	}
}